<template>
  <nav class="site-navbar" :class="'site-navbar--' + navbarLayoutType">
    <div class="site-navbar__header">
      <div class="site-navbar__brand" style="font-size: 20px; font-weight: 500" @click="$router.push({ name: routing })">
        <div class="site-navbar__brand-lg" href="javascript:;">
          <img src="../assets/img/logo.png" alt="" class="logo" />
          <span>财务清结算系统</span>
        </div>

        <div class="site-navbar__brand-mini" href="javascript:;">
          <img src="../assets/img/logo.png" alt="" class="logo" />
        </div>
      </div>
    </div>
    <div class="site-navbar__body clearfix">
      <el-menu class="site-navbar__menu" mode="horizontal">
        <el-menu-item class="site-navbar__switch" index="0" @click="sidebarFold = !sidebarFold">
          <icon-svg name="zhedie"></icon-svg>
        </el-menu-item>
        <el-menu-item class="site-navbar__avatar" index="3">
          <el-breadcrumb separator="/">
            <!-- <el-breadcrumb-item>峰高财务</el-breadcrumb-item> -->
            <el-breadcrumb-item>{{ mainTabsActiveName }}</el-breadcrumb-item>
          </el-breadcrumb>
        </el-menu-item>
      </el-menu>
      <el-menu class="site-navbar__menu site-navbar__menu--right" mode="horizontal">
        <!-- <el-menu-item index="1" @click="$router.push({ name: 'theme' })">
          <template slot="title">
            <el-badge value="new">
              <icon-svg name="shezhi" class="el-icon-setting"></icon-svg>
            </el-badge>
          </template>
        </el-menu-item> -->
        <!-- <el-menu-item index="2">
          <el-badge value="hot">
            <a href="https://www.renren.io/" target="_blank">官方社区</a>
          </el-badge>
        </el-menu-item> -->
        <!-- <el-submenu index="3">
          <template slot="title">Git源码</template>
          <el-menu-item index="2-1"><a href="https://github.com/renrenio/renren-fast-vue" target="_blank">前端</a></el-menu-item>
          <el-menu-item index="2-2"><a href="https://gitee.com/renrenio/renren-fast" target="_blank">后台</a></el-menu-item>
          <el-menu-item index="2-3"><a href="https://gitee.com/renrenio/renren-generator" target="_blank">代码生成器</a></el-menu-item>
        </el-submenu> -->
        <el-menu-item class="site-navbar__avatar" index="3">
          <el-dropdown :show-timeout="0" placement="bottom">
            <span class="el-dropdown-link">
              <img src="~@/assets/img/avatar.png" :alt="nickname" />
              {{nickname}}
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="updatePasswordHandle()">修改密码</el-dropdown-item>
              <el-dropdown-item @click.native="logoutHandle()">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-menu-item>
      </el-menu>
    </div>
    <!-- 弹窗, 修改密码 -->
    <update-password v-if="updatePassowrdVisible" ref="updatePassowrd"></update-password>
  </nav>
</template>

<script>
import UpdatePassword from "./main-navbar-update-password";
import { clearLoginInfo } from "@/utils";
// import { isURL } from '@/utils/validate'
export default {
  data () {
    return {
      updatePassowrdVisible: false,
      routing: localStorage.getItem("routing"),
      nickname: "",
    };
  },
  created () {
    // console.log(this.routing)
    if (this.routing === "subFinance-balanceDetails") {
      this.nickname =
        localStorage.getItem("legalCompanyName") +
        " - " +
        localStorage.getItem("employeeName");
    }
    else {
      this.nickname =
        localStorage.getItem("financeCompanyName") +
        " - " +
        localStorage.getItem("nickname");
    }
  },
  components: {
    UpdatePassword,
  },
  computed: {
    navbarLayoutType: {
      get () {
        return this.$store.state.common.navbarLayoutType;
      },
    },
    mainTabsActiveName: {
      get () {
        if (
          this.$store.state.common.mainTabsActiveName ===
          "totalFinance-packageManagement"
        ) {
          return "账套管理";
        } else if (
          this.$store.state.common.mainTabsActiveName ===
          "totalFinance-Withdrawal"
        ) {
          return "提现管理";
        } else if (
          this.$store.state.common.mainTabsActiveName ===
          "totalFinance-settlementList"
        ) {
          return "结算账单";
        } else if (
          this.$store.state.common.mainTabsActiveName ===
          "totalFinance-settlementDetail"
        ) {
          return "账单明细";
        } else if (
          this.$store.state.common.mainTabsActiveName ===
          "totalFinance-systemConfiguration"
        ) {
          return "系统配置";
        } else if (
          this.$store.state.common.mainTabsActiveName ===
          "totalFinance-WithdrawalRecord"
        ) {
          return "提现记录";
        } else if (
          this.$store.state.common.mainTabsActiveName ===
          "subFinance-WithdrawalRecord"
        ) {
          return "提现记录";
        } else if (
          this.$store.state.common.mainTabsActiveName ===
          "subFinance-settlementList"
        ) {
          return "结算账单";
        } else if (
          this.$store.state.common.mainTabsActiveName ===
          "subFinance-settlementDetail"
        ) {
          return "账单明细";
        } else if (
          this.$store.state.common.mainTabsActiveName ===
          "totalFinance-Grouppropertylist"
        ) {
          return "账单明细";
        } else if (
          this.$store.state.common.mainTabsActiveName ===
          "totalFinance-Grouphomelist"
        ) {
          return "账单明细";
        } else if (
          this.$store.state.common.mainTabsActiveName ===
          "subFinance-chargeDetails"
        ) {
          return "交易明细";
        } else if (
          this.$store.state.common.mainTabsActiveName ===
          "totalFinance-Groupproperty"
        ) {
          return "交易明细";
        } else if (
          this.$store.state.common.mainTabsActiveName ===
          "totalFinance-Grouphome"
        ) {
          return "交易明细";
        } else if (
          this.$store.state.common.mainTabsActiveName === "subFinance-automatic"
        ) {
          return "系统配置";
        } else if (
          this.$store.state.common.mainTabsActiveName === "subFinance-agreement"
        ) {
          return "用户协议";
        } else if (
          this.$store.state.common.mainTabsActiveName ===
          "totalFinance-reconciliation"
        ) {
          return "余额对账单";
        } else {
          if (
            localStorage.getItem("routing") == "totalFinance-balanceDetails"
          ) {
            return "余额管理";
          } else {
            return "提现管理";
          }
        }
      },
      set (val) {
        this.$store.commit("common/updateMainTabsActiveName", val);
      },
    },
    sidebarFold: {
      get () {
        return this.$store.state.common.sidebarFold;
      },
      set (val) {
        this.$store.commit("common/updateSidebarFold", val);
      },
    },
    mainTabs: {
      get () {
        return this.$store.state.common.mainTabs;
      },
      set (val) {
        this.$store.commit("common/updateMainTabs", val);
      },
    },
  },
  methods: {
    mainTabsActiveName (e) {
      console.log(e);
    },
    // 修改密码
    updatePasswordHandle () {
      this.updatePassowrdVisible = true;
      this.$nextTick(() => {
        this.$refs.updatePassowrd.init();
      });
    },
    // 退出
    logoutHandle () {
      this.$confirm(`确定进行[退出]操作?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          clearLoginInfo();

          this.$router.push({ name: "login" });
        })
        .catch(() => { });
    },
  },
};
</script>
<style scoped>
</style>
